package com.joplus.housekeeper.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListAdapter;
import android.widget.TextView;

import com.joplus.housekeeper.R;

/**
 * Created by zisheng on 2017/9/21.
 */

class RabitAdapter extends BaseAdapter {
    int[] gif1 = new int[]{R.drawable.u10001, R.drawable.u10002, R.drawable.u10003, R.drawable.u10004, R.drawable.u10005, R.drawable.u10006, R.drawable.u10007, R.drawable.u10008};
    int[] gif2 = new int[]{R.drawable.u10009, R.drawable.u10010,  R.drawable.u10011,  R.drawable.u10012,  R.drawable.u10013,  R.drawable.u10014,  R.drawable.u10015,  R.drawable.u10016,  };
    String[] gifCode1 = new String[]{"U10001", "U10002", "U10003", "U10004", "U10005", "U10006", "U10007", "U10008"};

    String[] gifCode2 = new String[]{"U10009", "U10010","U10011","U10012","U10013","U10014","U10015","U10016" };
    int[] gifS1 = new int[]{R.string.u10001, R.string.u10002, R.string.u10003, R.string.u10004, R.string.u10005, R.string.u10006, R.string.u10007, R.string.u10008};
    int[] gifS2 = new int[]{R.string.u10009, R.string.u10010, R.string.u10011, R.string.u10012, R.string.u10013, R.string.u10014, R.string.u10015,R.string.u10016};


    private final LayoutInflater layout;
    int outP = 0;
    Context context;

    public RabitAdapter(Context context, int gif1) {
        this.context = context;
        layout = LayoutInflater.from(context);
        outP = gif1;
    }

    @Override
    public int getCount() {
        return 8;
    }

    @Override
    public String getItem(int position) {
        if (outP == 0) {
            return gifCode1[position];
        } else {
            return gifCode2[position];
        }

    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view = layout.inflate(R.layout.item_image, null);
        ImageView iv = (ImageView) view.findViewById(R.id.iv);
        TextView tv = (TextView) view.findViewById(R.id.tv);
        if (outP == 0) {
            iv.setImageResource(gif1[position]);
            tv.setText(context.getString(gifS1[position]));
        } else {
            iv.setImageResource(gif2[position]);
            tv.setText(context.getString(gifS2[position]));
        }

        return view;
    }
}
